package com.yuanyu.server.impl;

import com.yuanyu.common.util.AssertUtil;
import com.yuanyu.common.util.CopyUtil;
import com.yuanyu.mapper.mysqlMapper.Assembly_record_of_dry_pump.Assembly_record_of_dry_pump_1_Mapper;
import com.yuanyu.mapper.mysqlMapper.Assembly_record_of_dry_pump.Assembly_record_of_dry_pump_Mapper;
import com.yuanyu.mapper.mysqlMapper.MainTable_Mapper;
import com.yuanyu.model.dto.Assembly_record_of_dry_pumpDTO;
import com.yuanyu.model.entity.Assembly_record_of_dry_pump.Assembly_record_of_dry_pump;
import com.yuanyu.model.entity.Assembly_record_of_dry_pump.Assembly_record_of_dry_pump_1;
import com.yuanyu.model.vo.Assembly_record_of_dry_pumpVO;
import com.yuanyu.server.ITestPart5Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
@Transactional
public class TestPart5ServerImpl implements ITestPart5Server {
    @Autowired
    private Assembly_record_of_dry_pump_Mapper assemblyRecordOfDryPumpMapper;
    @Autowired
    private Assembly_record_of_dry_pump_1_Mapper assemblyRecordOfDryPump1Mapper;
    @Autowired
    private MainTable_Mapper mainTableMapper;

    @Override
    public String test() {
        return "测试成功";
    }

    @Override
    public String test5(Assembly_record_of_dry_pumpVO assemblyRecordOfDryPumpVO) {
        Assembly_record_of_dry_pump test = assemblyRecordOfDryPumpMapper.selTableTime(assemblyRecordOfDryPumpVO.getInput_Case());
        AssertUtil.isNull(test,"Case已存在,如需修改内容请前往后台修改");

        Assembly_record_of_dry_pump assemblyRecordOfDryPump = new Assembly_record_of_dry_pump();
        Assembly_record_of_dry_pump_1 assemblyRecordOfDryPump1 = new Assembly_record_of_dry_pump_1();

        CopyUtil.copyClass(assemblyRecordOfDryPumpVO,assemblyRecordOfDryPump);
        assemblyRecordOfDryPump.setCreatedAt(LocalDateTime.now());
        assemblyRecordOfDryPump.setUpdatedAt(LocalDateTime.now());
        CopyUtil.copyClass(assemblyRecordOfDryPumpVO,assemblyRecordOfDryPump1);

        int i = assemblyRecordOfDryPumpMapper.addTableTime(assemblyRecordOfDryPump);
        int i1 = assemblyRecordOfDryPump1Mapper.addTable1(assemblyRecordOfDryPump1);

        AssertUtil.isTrue(i == 1 && i1 == 1,"添加数据出现异常,请检查");

        mainTableMapper.updateByCaseFormStartTime(assemblyRecordOfDryPumpVO.getInput_Case());
        return "添加成功";
    }

    @Override
    public String updateTable5(Assembly_record_of_dry_pumpVO assemblyRecordOfDryPumpVO) {
        Assembly_record_of_dry_pump assemblyRecordOfDryPump = new Assembly_record_of_dry_pump();
        Assembly_record_of_dry_pump_1 assemblyRecordOfDryPump1 = new Assembly_record_of_dry_pump_1();

        CopyUtil.copyClass(assemblyRecordOfDryPumpVO,assemblyRecordOfDryPump);
        assemblyRecordOfDryPump.setUpdatedAt(LocalDateTime.now());
        CopyUtil.copyClass(assemblyRecordOfDryPumpVO,assemblyRecordOfDryPump1);

        int i = assemblyRecordOfDryPumpMapper.updateTableTime(assemblyRecordOfDryPump);
        int i1 = assemblyRecordOfDryPump1Mapper.updateTable1(assemblyRecordOfDryPump1);

        AssertUtil.isTrue(i == 1 && i1 == 1,"表5修改数据出现异常,请检查");
        return "修改成功";
    }

    @Override
    public Assembly_record_of_dry_pumpDTO getTest5(String Case) {
        Assembly_record_of_dry_pump assemblyRecordOfDryPump = assemblyRecordOfDryPumpMapper.selTableTime(Case);
        if (assemblyRecordOfDryPump == null)return null;
        Assembly_record_of_dry_pump_1 assemblyRecordOfDryPump1 = assemblyRecordOfDryPump1Mapper.selTable1(Case);
        Assembly_record_of_dry_pumpDTO assemblyRecordOfDryPumpDTO = new Assembly_record_of_dry_pumpDTO();
        CopyUtil.copyClass(assemblyRecordOfDryPump,assemblyRecordOfDryPumpDTO);
        CopyUtil.copyClass(assemblyRecordOfDryPump1,assemblyRecordOfDryPumpDTO);
        return assemblyRecordOfDryPumpDTO;
    }
}
